package com.gaoyubo.configs;

import com.netflix.loadbalancer.BestAvailableRule;
import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.ResponseTimeWeightedRule;
import com.netflix.loadbalancer.RoundRobinRule;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

@Configuration
public class MyConfig {
    @Bean
    @LoadBalanced
    public RestTemplate getResttemplate(){
        return new RestTemplate();
    }
    //定义负载均衡的规则这种的配置是全局的
    /*@Bean
    public IRule randomRule(){
        return new RoundRobinRule();
    }*/
    /*@Bean
    public IRule bestAvailabRule(){
        return new BestAvailableRule();
    }*/
    @Bean
    public IRule responseTimeWeightedRule(){
        return new ResponseTimeWeightedRule();
    }
}
